<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%
	String path = request.getContextPath();
%>
<script type="text/javascript">
	jQuery(function($) {
		//var mapSize = "${menuMap.size()}";
		var mapSize = "${fn:length(menuMap)} ";
		for(var index=0;index<mapSize;index++){
			// 获取需要展示的对象
			var tree = $("#setMenuTree_" + index, navTab.getCurrentPanel());
			// 获取存储treeData值的对象
			var treeData = $("#setTreeData_" + index, navTab.getCurrentPanel());
			tree.html(getDWZTreeHTML2(
					eval('(' + treeData.val() + ')'),// data
					"",
					"menuNode"
			).replaceAll("<ul></ul>",""));
		}
		
		$("#btnSave",navTab.getCurrentPanel()).click(function() {
			setPrivilege();
		});
		
		$("#auth_list_roleList",navTab.getCurrentPanel()).change(function() {
			setCheck();
		});
		setCheck();
	});
	
	// 初始化选中菜单记录
	var menuList = new Array();
	
	function setPrivilege(){
		var groupId = $("#auth_list_groupList",navTab.getCurrentPanel()).val();
		var usrCode = $("#auth_list_roleList",navTab.getCurrentPanel()).val();
		if(groupId == ""){
			alertMsg.info("用户组不能为空！");
			return false;
		}
		if (usrCode == "") {
			alertMsg.info("角色不能为空！");
			return false;
		}
		
		$.post("userRole_setPrivilege.action", {
			"usrCode": usrCode,//usrCode
			"menuIds" : menuList.join(",")
		}, function(data) {
			//dialogAjaxDone(eval('(' + data + ')'));
			navTabAjaxDone(eval('(' + data + ')'));
		}, "text"); 
	}
	
	
	
	
	/** 获取选中checkbox  dwz文件修改 暂时废弃该方法 目前问题为 选中子级其父级及同级皆被选中 */
	function getSelectMenus(groupName) {
        var result = "";
        $("input:checkbox[name=" + groupName + "]:checked",navTab.getCurrentPanel()).each(
	        function(i, a) {
	            result += "," + a.value;
        });
 
        if (result.length > 0) {
            result = result.substring(1);
        }
        return result;
    }

 /* 	
	
	//Jquery初始化
	$(document).ready(function() {
		$("#btnSave").click(function() {
			save();
		});
		$("#auth_list_roleList").change(function() {
			setCheck();
		});
		setCheck();
	});*/

	//设置Tree选中
	function setCheck() {
		//menuList ={};
		var whichEl = document.getElementsByName("menuNode");
		for(var i = 0; i< whichEl.length; i++){
			whichEl[i].parentNode.className="ckbox unchecked";
		}
		var usrCode = $("#auth_list_roleList").val();
		if (usrCode != "") {
			$.ajax({
				url : "userRole_getPrivilege.action",
				type : "post",
				data : {
					"usrCode" : usrCode
				},
				dataType : "json",
				success : function(result) {
					$.each(eval('(result)'), function(i, item) {
						var whichEl = document.getElementsByName("menuNode");
						for(var j =0; j<whichEl.length; j++){
							 if(whichEl[j].value == item.menuId){
								menuList[j] = whichEl[j].value;
								if(whichEl[j].parentNode.className!="ckbox checked")
								whichEl[j].parentNode.className="ckbox checked";
							} 
						}
					});
				}
			});
		}
	} 
	
	/** 选中节点事件 */
	function checkNode() {
		if($("#auth_list_groupList").val()==""){
			alertMsg.info("请先选择用户组！");
		}else if($("#auth_list_roleList").val()==""){
			alertMsg.info("请先选择角色！");
		}
		
		menuList=new Array();
		$("div.checked").each(function(i){  
			menuList[i]=$(this).children().val();  
		}); 
		
	} 
	
</script>
<style>
<!--
.sysdc{
	float:left; 
	display:block; 
	margin:10px; 
	overflow:auto; 
	width:240px; 
	height:516px; 
	overflow:auto; 
	border:solid 1px #CCC; 
	line-height:21px; 
	background:#FFF;
}
-->
</style>
<div class="pageHeader">
	<div class="searchBar nowrap">
		<p>
			<label>用户组：</label>
			<select id="auth_list_groupList" 
				name="sysUserGroup.usgName"
				class="combox"
				ref="auth_list_roleList"
				refUrl="userRole_getRoleList2.action?usgCode={value}">
				<option value="">---所有用户组---</option>
				<c:forEach items="${userGroupList}" var="group">
					<option value="${group.usgCode }">${group.usgName}</option>
				</c:forEach>
			</select>
		</p>
		<p>
			<label>角&nbsp;&nbsp;色：</label>
			<select name="isuRoleCode" id="auth_list_roleList" class="combox">
				<option value="" >---所有角色---</option>
			</select>
		</p>
		<!-- 
		<table class="searchContent" >
			<tr>
				<td>
					<label>用户组：${sysUserGroup.usgName }</label>
					<select id="auth_list_groupList" 
						name="sysUserGroup.usgName"
						class="combox"
						ref="auth_list_roleList"
						refUrl="userRole_getRoleList2.action?usgCode={value}">
						<option value="">---所有用户组---</option>
						<c:forEach items="${userGroupList}" var="group">
							<option value="${group.usgCode }">${group.usgName}</option>
						</c:forEach>
					</select>
				</td>
				<td>
					<label>角&nbsp;&nbsp;色：</label>
					<select name="isuRoleCode" id="auth_list_roleList" class="combox">
						<option value="" >---所有角色---</option>
					</select>
				</td>
			</tr>
		</table>
		 -->
	</div>
</div>
<div class="pageContent">
<c:forEach items="${menuMap }" var="menuMap" varStatus="status">
<div class="sysdc" layoutH="95">
	<h2 class="contentTitle">${menuMap.key}</h2>
	<input id="setTreeData_${status.index }" type="hidden" value="${menuMap.value}">
	<div layoutH="140" name="setMenuTree" id="setMenuTree_${status.index }">
	
	</div>
</div>
</c:forEach>


<%--
<c:forEach items="${menuMap }" var="menuMap">
<div class="sysdc" layoutH="95">
	<h2 class="contentTitle">${menuMap.key}</h2>
	<ul class="tree treeFolder treeCheck expand" oncheck="checkNode">
		<c:forEach items="${menuMap.value}" var="menu" >
			<c:if test="${empty menu.parent}">
				<li>
					<a tname="name" name="dwztree"  tvalue="${menu.menuId}">${menu.menuName}</a>
					<c:forEach items="${menuMap.value}"	var="menuChild" >
						<ul>
						<c:if test="${menuChild.parent.menuId==menu.menuId}">
							<li><a tname="name" name="dwztree" tvalue="${menuChild.menuId}" >${menuChild.menuName}</a></li>
						</c:if>
						</ul>
					</c:forEach>
				</li>
			</c:if>
		</c:forEach>

	</ul>
</div>

</c:forEach>
 --%>
<div class="formBar">
	<ul>
		<li><div class="buttonActive">
				<div class="buttonContent">
					<button type="button" id="btnSave">设置</button>
				</div>
			</div></li>
		<li>
			<div class="button">
				<div class="buttonContent">
					<button type="button" class="close">取消</button>
				</div>
			</div>
		</li>
	</ul>
</div>
</div>